<template>
	<view>
		<nav-back></nav-back>

		<view class="title">
			<text>请输入昵称 </text>
		</view>

		<view class="nickname">
			<view class="my-input">
				<input class="uni-input" name="nickname" @input="handleName" placeholder="请输入昵称" />
			</view>
			<view class="tip">
				<image src="/static/img/tip.png" mode="" />
				只能由字母、数字、下划线和中文组成，最少三位
			</view>
		</view>

		<button class="next" type="primary" @click="handleNext">下一步</button>

	</view>
</template>

<script>
	import request from '@/utils/request.js'
	import NavBack from '@/components/NavBack.vue'

	export default {
		components: {
			NavBack
		},
		data() {
			return {
				nickname: ''
			}
		},
		methods: {
			handleName(e) {
				console.log(e.detail.value, 'handleName');
				this.nickname = e.detail.value
			},
			handleNext() {
				let nicknameReg = /^[a-zA-Z0-9_\u4e00-\u9fa5]{3,}$/;
				if (!this.nickname) {
					uni.showToast({
						title: '请输入昵称',
						icon: 'none',
						duration: 2000
					})
					return
				}
				if (nicknameReg.test(this.nickname)) {
					console.log("格式正确");
					getApp().globalData.userInfo.name = this.nickname
					console.log(this.nickname, 'this.nickname');
					uni.redirectTo({
						url: '/pages/userInfo/birthDay/birthDay'
					})
				} else {
					console.log("格式错误");
					uni.showToast({
						title: '昵称格式错误',
						icon: 'none',
						duration: 2000
					})
				}
			},
		}
	}
</script>

<style lang="scss">
	@import "@/style/register.scss";

	.nickname {
		margin-top: 200rpx;

		.my-input {
			border-radius: 50rpx;
		}

		.tip {
			display: flex;
			align-items: center;
			margin-top: 20rpx;
			font-size: 24rpx;
			color: rgba(102, 102, 102, 1);

			image {
				width: 32rpx;
				height: 32rpx;
				margin: 0 10rpx;
			}
		}
	}
</style>